package KnightsTour.GUI;

import KnightsTour.ChessBoard;
import KnightsTour.SquareColour;
import java.awt.*;
import javax.swing.*;

/**
 *
 * @author Scott Robinson
 */
public class ChessboardPanel extends JPanel {

    private ChessBoard cb;
    private final Color LIGHT_BLUE = new Color (195,214,242);
    private final SquarePanel sp [][];
    private final static int PREF_SIZE = 70;


    public ChessboardPanel (int prefSize, ChessBoard chessBoard) {
        this.cb = chessBoard;
        sp = new SquarePanel[cb.ROWS][cb.COLUMNS];
        setLayout(new GridLayout(cb.ROWS,cb.COLUMNS));
        for (int r = 0; r < cb.ROWS  ; r++ ) {
            for (int c = 0; c < cb.COLUMNS ; c++ ) {
                if (cb.getChessBoardSquare(r, c).getColour() == SquareColour.WHITE) {
                    sp [r][c] = new SquarePanel(cb.getChessBoardSquare(r, c));
                }
                else {
                    sp [r][c] = new SquarePanel ( LIGHT_BLUE, cb.getChessBoardSquare(r, c) );
                }
                add(sp[r][c]);
            }
        }
    }

    public ChessboardPanel (ChessBoard cb) {
        this (PREF_SIZE, cb);
    }

    public ChessBoard getChessBoard () {
        return cb;
    }
    

    public SquarePanel getChessBoardSquarePanel (int row, int column) {
        return sp[row][column];
    }

    public SquarePanel [][] getAllSquares () {
        return sp;
    }


}
